home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CDICTION
/
CSMARTED.C
< prev
next >
Wrap
Text File
|
1990-01-12
|
8KB
|
296 lines
/*****************************************************************************
CSmartEditText.c
see header for information
SUPERCLASS = CEditText
*****************************************************************************/
#include "CSmartEditText.h"
#include "CSmartDocument.h"
#include "CSmartWindow.h"
#include "Commands.h"
#include "CSmartTETask.h"
/*****************************************************************************/
void CSmartEditText::ISmartEditText(CView *anEnclosure, CBureaucrat *aSupervisor,
Int16 aWidth, Int16 aHeight,
Int16 aHEncl, Int16 aVEncl,
SizingOption aHSizing, SizingOption aVSizing,
Int16 aLineWidth, Int16 firstTaskIndex)
/*
All parameters are standard, with the exception of firstTaskIndex.
This should give the index into the STR# 130 (STRtaskNames) resource
where the undo strings reside. Strings for cut,copy,paste,clear,type
commands are required (and in that order). firstTaskIndex gives the
index for cut.
TCL assumes all undo strings are located in this resource.
*/
{
CSmartWindow *window;
/* Get the window that (ultimately) encloses us. We can't assume
that the window is our immediate enclosure or the document is
our immediate supervisor so we do something a little dirty
to get the window and document */
window = (CSmartWindow *) GetWRefCon( anEnclosure->GetMacPort());
if (member( window, CSmartWindow))
{
/* Since TextEdit will pick up its font characteristics
from the current port, we want to be sure the port is
in its preferred state (if it has one) before TENew()
is called. */
window->RestoreEnvirons();
itsSmartDoc = (CSmartDocument *) window->itsSupervisor;
}
else itsSmartDoc = NIL;
CEditText::IEditText( anEnclosure, aSupervisor, aWidth, aHeight, aHEncl,
aVEncl, aHSizing, aVSizing, aLineWidth);
if (itsSmartDoc)
itsSmartDoc->AddEditItem( this); /* register in doc's list */
isKeyTarget = FALSE;
dirty = FALSE;
editable = TRUE;
passReturns = FALSE;
itsCurrentTask = NIL;
this->firstTaskIndex = firstTaskIndex;
GetSelection( &lastSelect.h, &lastSelect.v);
} /* CSmartEditText::ISmartEditText */
/*****************************************************************************/
void CSmartEditText::DoCommand(Int32 theCommand)
{
if ((theCommand >= cmdCut) && (theCommand <= cmdClear))
{
MakeTETask( (tTE_Command) theCommand - cmdCut);
inherited::DoCommand( theCommand);
itsSupervisor->Notify( itsCurrentTask);
}
else inherited::DoCommand( theCommand);
} /* CSmartEditText::DoCommand */
/*****************************************************************************/
void CSmartEditText::DoClick(Point hitPt, short modifierKeys, long when)
{
/* DoClick is not called unless we are editable */
extern CSmartEditText *gEditText;
if ( !isKeyTarget && itsSmartDoc)
{
itsSmartDoc->ActivateEditItem( this);
}
inherited::DoClick( hitPt, modifierKeys, when);
} /* CSmartEditText::DoClick */
/*****************************************************************************/
void CSmartEditText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
{
/* we should never be the gopher if we're not editable
but just in case... */
if (!editable)
{
itsSupervisor->DoKeyDown( theChar, keyCode, macEvent);
return;
}
if (itsSmartDoc &&(theChar == kTab))
{
itsSmartDoc->ActivateNextEditItem( this);
}
else
{
Boolean madeNewTask = FALSE;
if (((theChar == kCR)||(theChar == kEnter)) && passReturns)
itsSupervisor->DoKeyDown( theChar, keyCode, macEvent);
else
{
if ((theChar >= kClearKey) && (theChar <= kDownArrow))
{
Point sel;
inherited::DoKeyDown( theChar, keyCode, macEvent);
}
else
{
Point currSelect;
GetSelection( &currSelect.h, &currSelect.v);
if (!EqualPt( currSelect, lastSelect))
{
if (itsCurrentTask)
{
Notify( NIL);
itsCurrentTask = NIL;
}
}
if (!itsCurrentTask)
{
MakeTETask( teType);
madeNewTask = TRUE;
}
inherited::DoKeyDown( theChar, keyCode, macEvent);
GetSelection( &lastSelect.h, &lastSelect.v);
if (madeNewTask) itsSupervisor->Notify( itsCurrentTask);
}
}
}
} /* CSmartEditText::DoKeyDown */
/*****************************************************************************/
void CSmartEditText::Hide( void)
{
/* inherited::Hide will leave insertion point showing */
if (active)
{
if (itsSmartDoc)
itsSmartDoc->ActivateNextEditItem( this);
Deactivate();
}
inherited::Hide();
} /* CSmartEditText::Hide */
/*****************************************************************************/
void CSmartEditText::SetTarget( Int16 isTarget)
{
isKeyTarget = isTarget != 0;
if (isKeyTarget)
{
Activate();
}
else
{
Deactivate();
SetSelection( 0, 0);
}
} /* CSmartEditText::SetTarget */
/*****************************************************************************/
void CSmartEditText::GetSelection( Int16 *startSel, Int16 *endSel)
{
*startSel = (**macTE).selStart;
*endSel = (**macTE).selEnd;
} /* CSmartEditText::GetSelection */
/*****************************************************************************/
void CSmartEditText::SetSelection( Int16 startSel, Int16 endSel)
{
TESetSelect( startSel, endSel, macTE);
} /* CSmartEditText::SetSelection */
/*****************************************************************************/
void CSmartEditText::SelectAll( void)
{
SetSelection( 0, MAXINT);
} /* CSmartEditText::SelectAll */
/*****************************************************************************/
void CSmartEditText::ClearText( void)
{
Handle h = NewHandle( 0);
if (h)
{
SetTextHandle(h);
DisposHandle(h);
}
} /* CSmartEditText::ClearText */
/*****************************************************************************/
Boolean CSmartEditText::IsDirty( void)
{
return dirty;
} /* CSmartEditText::IsDirty */
/*****************************************************************************/
void CSmartEditText::SetDirty( Boolean dirty)
{
this->dirty = dirty;
} /* CSmartEditText::SetDirty */
/*****************************************************************************/
Int16 CSmartEditText::GetLineCount( void)
{
Int16 numLines;
numLines = (**macTE).nLines;
if ((!numLines)||(GetLastChar() == kCR)) numLines++;
return numLines;
} /* CSmartEditText::GetLineCount */
/*****************************************************************************/
char CSmartEditText::GetLastChar( void)
{
return *(*(**macTE).hText + (**macTE).teLength - 1);
} /* CSmartEditText::GetLastChar */
/*****************************************************************************/
void CSmartEditText::SetEditable( Int16 canEdit)
{
editable = canEdit;
if (!canEdit)
{
if (isKeyTarget)
{
SetSelection( 0, 0);
itsSmartDoc->ActivateNextEditItem( this);
}
}
SetWantsClicks( editable);
} /* CSmartEditText::SetEditable */
/*****************************************************************************/
Boolean CSmartEditText::IsEditable( void)
{
return editable;
} /* CSmartEditText::IsEditable */
/*****************************************************************************/
void CSmartEditText::SetPassReturns( Int16 passFlag)
{
passReturns = passFlag;
} /* CSmartEditText::SetPassReturns */
/*****************************************************************************/
Boolean CSmartEditText::GetPassReturns( void)
{
return passReturns;
} /* CSmartEditText::GetPassReturns */
/*****************************************************************************/
void CSmartEditText::GetString( StringPtr string)
/*
returns first 255 chars (or less) as a pascal string.
*/
{
Int16 length;
Handle h;
h = GetTextHandle();
length = MIN( 255, GetHandleSize(h));
string[0] = length;
BlockMove( *h, &string[1], length);
} /* CSmartEditText::GetString */
/*****************************************************************************/
void CSmartEditText::MakeTETask( tTE_Command theCommand)
{
CSmartTETask* theTask = NIL;
theTask = new( CSmartTETask);
theTask->ISmartTETask( this, firstTaskIndex, theCommand);
itsCurrentTask = theTask;
} /* CSmartEditText::MakeTETask */
/*****************************************************************************/